package net.common.log;

import org.apache.log4j.Logger;
import org.apache.log4j.xml.DOMConfigurator;

/**
 * 日志处理类,主要使用Log4j进行处理
 * 
 * @author 孙树林
 * 
 */
public class Log {

	private static Log logger;

	private static Logger log4j = Logger.getLogger(Log.class); // log4j

	/**
	 * 构造器,实例化log4j
	 * 
	 * @param name
	 */
	private Log(String name) {
		log4j = Logger.getLogger(name);
	}

	/**
	 * log实例
	 * 
	 * @param name
	 * @return
	 */
	public static Log getInstance(String name) {
		if (logger == null) {
			logger = new Log(name);
		}
		return logger;
	}

	/**
	 * debug
	 * 
	 * @param str
	 */
	public void debug(String str) {
		log4j.debug(str);
	}

	/**
	 * debug
	 * 
	 * @param obj
	 * @param str
	 */
	public void debug(Object obj, String str) {
		log4j.debug(obj.getClass() + " " + str);
	}

	/**
	 * info
	 * 
	 * @param str
	 */
	public void info(String str) {
		log4j.info(str);
	}

	/**
	 * info
	 * 
	 * @param str
	 */
	public void info(Object obj, String str) {
		log4j.info(obj.getClass() + " " + str);
	}

	/**
	 * error
	 * 
	 * @param str
	 */
	public void error(String str) {
		log4j.error(str);
	}

	/**
	 * error
	 * 
	 * @param str
	 */
	public void error(String str, Throwable throwable) {
		log4j.error(str, throwable);
	}

	/**
	 * error
	 * 
	 * @param str
	 */
	public void error(Object obj, String str) {
		log4j.error(obj.getClass() + " " + str);
	}

	/**
	 * error
	 * 
	 * @param str
	 */
	public void error(Object obj, Throwable throwable, String str) {
		log4j.error(obj.getClass() + " " + str, throwable);
	}

	/**
	 * error
	 * 
	 * @param str
	 */
	public void error(String strPath, Throwable throwable, String str) {
		log4j.error(strPath + " " + str, throwable);
	}

	/**
	 * 加载log4j配置xml文件
	 * 
	 * @param path
	 */
	public static void init(String path) {
		DOMConfigurator.configure(path);
	}
}
